package com.example.module_patrol.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.example.module_patrol.R
import com.example.module_patrol.model.PatrolNotDoingEntity
import com.google.gson.Gson


class PatrolNotDoingAdapter :RecyclerView.Adapter<PatrolNotDoingAdapter.PatrolNotDoingViewHolder>() {
    var pakingList: ArrayList<PatrolNotDoingEntity> = arrayListOf()

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PatrolNotDoingViewHolder {
        return PatrolNotDoingViewHolder(
            LayoutInflater.from(parent.context).inflate(R.layout.item_notdoing, parent, false)
        )
    }

    override fun getItemCount(): Int {
        return pakingList.size
    }

    fun addParkingList(list: List<PatrolNotDoingEntity>) {
        pakingList.clear()
        pakingList.addAll(list)
        notifyDataSetChanged()
    }
    fun addSearchParking(entity:PatrolNotDoingEntity) {
        pakingList.clear()
        pakingList.add(entity)
        notifyDataSetChanged()
    }

    override fun onBindViewHolder(holder: PatrolNotDoingViewHolder, position: Int) {
        holder.name.text = pakingList[position].taskName
        holder.time.text = pakingList[position].patrolTime
        holder.type.text = "默认巡检"

        holder.itemView.setOnClickListener {
            val json = Gson().toJson(pakingList[position])
            ARouter.getInstance().build("/patrol/NotDoingDetailActivity")
                .withString("entity",json)
                .navigation()
        }
        }


   inner class PatrolNotDoingViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val name: TextView = itemView.findViewById(R.id.name)
        val time: TextView = itemView.findViewById(R.id.time)
        val type: TextView = itemView.findViewById(R.id.type)

    }

    }













